package com.micheal.mybatis.self;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by micheal on 2018/4/10/0010.
 */
public class MicMapperProxy implements InvocationHandler {

    private MicSqlSession sqlSession;

    public MicMapperProxy(MicSqlSession sqlSession) {
        this.sqlSession = sqlSession;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if(method.getDeclaringClass().getName().equals(MicConfiguration.XmlTestMapper.namespace)){
            String sql = MicConfiguration.XmlTestMapper.methodSqlMapping.get(method.getName());
            return sqlSession.selectOne(sql, String.valueOf(args[0]));
        }
        return method.invoke(method, args);
    }
}
